package com.pass.util;


import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class MD5Util {

    // 计算 Sign
    public static String springRainSign(String partner_key, String atime, String user_id)
            throws NoSuchAlgorithmException {
        String info = partner_key + atime + user_id;
        MessageDigest md5 = MessageDigest.getInstance("MD5");
        byte[] srcBytes = info.getBytes();
        md5.update(srcBytes);
        byte[] resultBytes = md5.digest();
        String hexStr = "";
        for (int i = 0; i < resultBytes.length; i++) {
            hexStr += DataTool.Byte2Hex(resultBytes[i]);
        }
        return hexStr.substring(8, 24).toLowerCase();
    }

    public static String getSign(String info)
            throws NoSuchAlgorithmException {
        MessageDigest md5 = MessageDigest.getInstance("MD5");
        byte[] srcBytes = info.getBytes();
        md5.update(srcBytes);
        byte[] resultBytes = md5.digest();
        String hexStr = "";
        for (int i = 0; i < resultBytes.length; i++) {
            hexStr += DataTool.Byte2Hex(resultBytes[i]);
        }
        return hexStr;
    }

}
